#include<stdio.h>
#include<stdlib.h>
typedef struct number
{
    int data;
    struct number *ptr;
}num;

num*  addnum(num *head,int adddata )
{
    num *current=head;
    num *add=(num*)malloc(sizeof(num));
    if(head==NULL)
    {
        head=add;
    }
   else
   {
        while(current->ptr!=NULL)
        {
            current=current->ptr;
        }
        current->ptr=add;
    }
    add->data=adddata;
    add->ptr=NULL;
    return head;
}

int countnum(num* head)
{
    int ret=1;
    while(head->ptr!=NULL)
    {
        ret++;
        head=head->ptr;
    }
    return ret;
}

num* sortnum(num* head,int count)
{
    if(count==1)
    {
        return head;
    }
    else if(count==2)
    {
        num* temp1,*temp2;
        temp1=head;
        temp2=head->ptr;
        if(head->data>temp2->data)
        {
            head=temp2;
            temp2->ptr=temp1;
            temp1->ptr=NULL;
        }
        return head;
    }
    else 
    {
        num *current,*temp1,*temp2;
        int flag=1;
        for(;count>1;count--)
        {
            current=head;
            temp1=current->ptr;
            flag=1;
            while(temp1->ptr!=NULL)
            {

                temp2=temp1->ptr;
                if(flag==1)
                {
                    if(current->data>temp1->data)
                    {
                        head=temp1;
                        current->ptr=temp1->ptr;
                        temp1->ptr=current;
                        current=head;
                        temp1=current->ptr;
                    }
                   
                    flag=0;
                }
                else
                {
                    if(temp1->data>temp2->data)
                    {
                        current->ptr=temp2;
                        temp1->ptr=temp2->ptr;
                        temp2->ptr=temp1;
                        current=current->ptr;
                    }
                    else
                    {
                        current=current->ptr;
                        temp1=temp1->ptr;
                    }
                }

            }
        }
        return head;
    }
}

void shownum(num* head)
{
    num* current=head;
    printf("The new list is:");
    while(current->ptr!=NULL)
    {
        printf("%d ",current->data);
        current=current->ptr;
    }
    printf("%d\n",current->data);
    
    
}

void delenum(num *head)
{
    num*current=head;
    while(current->ptr!=NULL)
    {
        current=current->ptr;
        free(head);
        head=current;
    }
}

int main()
{
    int a,count;
    num* head=NULL;
    while(1)
    {
        scanf("%d",&a);
        if(a==-1)
        {
            break;
        }
        else{
           head=addnum(head,a);
        }
    }

    count=countnum(head);
    head=sortnum(head,count);
    shownum(head);
    delenum(head);

      
   
   
    
    
    return 0;
}